Skip to content

INFRA-388 Converting smartmon into python and adding mock tests #1327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: stackhpc/2024.1
Choose a base branch
from

Conversation

technowhizz
Copy link
Contributor

No description provided.

@technowhizz technowhizz self-assigned this Oct 11, 2024
Copy link
Member

@dougszumski dougszumski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great start, many thanks. It would be good to investigate external libraries for the smart data collection / parsing.

@Alex-Welsh Alex-Welsh added stackhpc-ci Caracal Targets the Caracal OpenStack release labels Nov 15, 2024
@Alex-Welsh Alex-Welsh added enhancement New feature or request and removed stackhpc-ci labels Nov 22, 2024
@technowhizz technowhizz changed the title Converting smartmon into python and adding mock tests INFRA-388 Converting smartmon into python and adding mock tests Dec 13, 2024
Copy link
Member

@dougszumski dougszumski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @technowhizz , good effort.


def create_mock_device_from_json(self, device_info, if_attributes=None):
"""
Given a 'device_info' dict and optional 'if_attributes', build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create an actual pySmart device object here from the file output?
Eg. https://github.com/truenas/py-SMART/blob/master/tests/test_device.py#L43

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I gave this a shot but it turns out that it also requires a mock for smartctl and this made it a lot more complicated to just use a pySmart device. I think it makes more sense to mock it here

for metric in sorted(metrics):
metric_name = metric.split("{")[0]
if metric_name != last_metric:
output.append(f"# HELP smartmon_{metric_name} SMART metric {metric_name}")
Copy link
Member

@dougszumski dougszumski Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you switch to the Prometheus library here? It is a slight change that it will write directly to a file for scraping. The advantage is that it handles all the metric formatting. A rough example:

from prometheus_client import CollectorRegistry, Gauge, write_to_textfile

metric_registry = CollectorRegistry()
metric_output_path = os.environ['SMART_METRIC_OUTPUT_PATH'])

for metric in metrics:
   g = Gauge(metric_name, 'some help stirng', registry=registry)
   g.set(metric_value)

write_to_textfile(metric_output_path, registry)

https://prometheus.github.io/client_python/exporting/textfile/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Caracal Targets the Caracal OpenStack release enhancement New feature or request size: l
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants